home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / libgutil / glstuff.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  6KB  |  335 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    glstuff -
  19.  *        Graphics library support.
  20.  *
  21.  *                Paul Haeberli - 1988
  22.  *
  23.  */
  24. #include "math.h"
  25. #include "gl.h"
  26. #include "device.h"
  27. #include "stdio.h"
  28. #include "port.h"
  29. #include "bitmap.h"
  30. #include "obj.h"
  31. #include "gfxmach.h"
  32.  
  33. pupcolor(c)
  34. int c;
  35. {
  36.     color(c);
  37. }
  38.  
  39. greybase()
  40. {
  41.     return 512;
  42. }
  43.  
  44. extern int system(const char *);
  45.  
  46. savewindow(name)
  47. char *name;
  48. {
  49.     char cmd[256];
  50.     long xorg, yorg;
  51.     long xsize, ysize;
  52.  
  53.     getorigin(&xorg,&yorg);
  54.     getsize(&xsize,&ysize);
  55.     sprintf(cmd,"scrsave %s %d %d %d %d\n",name,xorg,xorg+xsize-1,yorg,yorg+ysize-1);
  56.     system(cmd);
  57. }
  58.  
  59. printwindow()
  60. {
  61.     savewindow("/usr/tmp/print.rgb");
  62.     system("printimage /usr/tmp/print.rgb");
  63.     system("rm /usr/tmp/print.rgb");
  64.     ringbell();
  65.     ringbell();
  66. }
  67.  
  68. saveframe()
  69. {
  70.     char oneline[512];
  71.  
  72.     savewindow("frame.rgb");
  73.     system("izoom frame.rgb vidframe.rgb 646");
  74.     system("rcp vidframe.rgb guest@cl2devi:/usr/people/paul");
  75.     sprintf(oneline,"/usr/bsd/rsh cl2devi -l paul vid/expose vidframe.rgb");
  76.     system(oneline);
  77.     system("rm frame.rgb vidframe.rgb");
  78. }
  79.  
  80. static int outframe = 0;
  81.  
  82. savemovieframe()
  83. {
  84.     char oneline[256];
  85.  
  86.     if(outframe++ == 0) {
  87.     system("rm -fr ssmovie");
  88.     system("mkdir ssmovie");
  89.     }
  90.     sprintf(oneline,"ssmovie/%03d.rgb",outframe);
  91.     savewindow(oneline); 
  92.     ringbell();
  93.     ringbell();
  94. }
  95.  
  96. static int gfxmach = -1;
  97. static long setnear, setfar;
  98.  
  99. gfxmachine()
  100. {
  101.     char str[256];
  102.  
  103.     if(gfxmach>=0)
  104.     return gfxmach;
  105.     gversion(str);
  106.     if(strncmp(str,"GL4DGT-",7) == 0)
  107.     return MACH4DGT;
  108.     if(strncmp(str,"GL4DPI",6) == 0) {
  109.     if(getplanes()<=8)
  110.         return MACH4D8;
  111.     else
  112.         return MACH4DPI;
  113.     } 
  114.     if(strncmp(str,"GL4D-",5) == 0)
  115.     return MACH4D;
  116.     if(strncmp(str,"GL3D-",5) == 0)
  117.     return MACH3D;
  118.     if(strncmp(str,"GL4DLG-",7) == 0)
  119.     return MACH4DVGX;
  120.     if(getplanes()<=8)
  121.     return MACH4D8;
  122.     else
  123.     return MACH4DVGX;
  124. }
  125.  
  126. smartsetdepth()
  127. {
  128.     fsetdepth(0.01,0.99);
  129. }
  130.  
  131. static int firsted;
  132. static double limnear, limdel;
  133.  
  134. fsetdepth(near,far)
  135. float near, far;
  136. {
  137.     int inear, ifar;
  138.  
  139.     if(!firsted) {
  140.     limnear = getgdesc(GD_ZMIN);
  141.     limdel = (double)getgdesc(GD_ZMAX)-limnear;
  142.     firsted = 1;
  143.     }
  144.     if(near<0.0)
  145.     near = 0.0;
  146.     if(far<0.0)
  147.     far = 0.0;
  148.     if(near>1.0)
  149.     near = 1.0;
  150.     if(far>1.0)
  151.     far = 1.0;
  152.     inear = (limnear+near*limdel)+0.499;
  153.     ifar  = (limnear+far *limdel)+0.499;
  154.     zviewport(inear,ifar);
  155. }
  156.  
  157. zviewport(near,far)
  158. long near, far;
  159. {
  160.     lsetdepth(near,far);
  161.     setnear = near;
  162.     setfar = far;
  163. }
  164.  
  165. getzviewport(lnear,lfar)
  166. long *lnear, *lfar;
  167. {
  168.     *lnear=setnear;
  169.     *lfar=setfar;
  170. }
  171.  
  172. drawmeshimage(imgdata,xsize,ysize)
  173. unsigned long *imgdata;
  174. int xsize, ysize;
  175. {
  176.     drawquadlimage(imgdata,xsize,ysize);
  177. }
  178.  
  179. drawquadlimage(imgdata,xsize,ysize)
  180. unsigned long *imgdata;
  181. int xsize, ysize;
  182. {
  183.     int x, y;
  184.     unsigned long *dptr;
  185.  
  186.     dptr = imgdata;
  187.     pushmatrix();
  188.     scale(1.0/(xsize-1),1.0/(ysize-1),1.0);
  189.     for(y=0; y<(ysize-1); y++) {
  190.     quadrow(dptr,dptr+xsize,xsize,y);
  191.     dptr += xsize;
  192.     }
  193.     popmatrix();
  194. }
  195.  
  196. quadrow(y0,y1,n,y)
  197. unsigned long *y0, *y1;
  198. int n, y;
  199. {
  200.     float v0[2], v1[2];
  201.     int x;
  202.     
  203.     v0[1] = y+0;
  204.     v1[1] = y+1;
  205.     bgntmesh();
  206.     for(x=0; x<n; x++) {
  207.     v1[0] = x;
  208.     cpack(*y1++);
  209.     v2f(v1);
  210.     v0[0] = x;
  211.     cpack(*y0++);
  212.     v2f(v0);
  213.     }
  214.     endtmesh();
  215. }
  216.  
  217. drawtrilimage(imgdata,xsize,ysize)
  218. unsigned long *imgdata;
  219. int xsize, ysize;
  220. {
  221.     int x, y, dxsize;
  222.     unsigned long *dptr;
  223.  
  224.     ysize = (ysize-1)/2;
  225.     dxsize = 2*((xsize-1)/2);
  226.     dptr = imgdata;
  227.     pushmatrix();
  228.     scale(1.0/(dxsize-1),1.0/ysize,1.0);
  229.     for(y=0; y<ysize; y++) {
  230.     trirow(dptr,dptr+2*xsize,dxsize,y);
  231.     dptr += 2*xsize;
  232.  
  233.     }
  234.     popmatrix();
  235. }
  236.  
  237. trirow(y0,y1,n,y)
  238. unsigned long *y0, *y1;
  239. int n, y;
  240. {
  241.     float v0[2], v1[2];
  242.     unsigned long *temp;
  243.     int x;
  244.     
  245.     if(y&1) {
  246.     temp = y0;
  247.     y0 = y1;
  248.     y1 = temp;;
  249.     v0[1] = y+1;
  250.     v1[1] = y+0;
  251.     } else {
  252.     v0[1] = y+0;
  253.     v1[1] = y+1;
  254.     }
  255.     bgntmesh();
  256.     v1[0] = 0;
  257.     cpack(y1[0]);
  258.     v2f(v1);
  259.     for(x=0; x<n; x++) {
  260.     if(x&1) {
  261.         v1[0] = x;
  262.         cpack(y1[x]);
  263.         v2f(v1);
  264.     } else {
  265.         v0[0] = x;
  266.         cpack(y0[x]);
  267.         v2f(v0);
  268.     }
  269.     }
  270.     if(n&1) {
  271.     v1[0] = n-1;
  272.     cpack(y1[n-1]);
  273.     v2f(v1);
  274.     } else {
  275.     v0[0] = n-1;
  276.     cpack(y0[n-1]);
  277.     v2f(v0);
  278.     }
  279.     endtmesh();
  280. }
  281.  
  282. drawrectlimage(imgdata,xsize,ysize)
  283. unsigned long *imgdata;
  284. int xsize, ysize;
  285. {
  286.     int x, y;
  287.     unsigned long *dptr;
  288.  
  289.     dptr = imgdata;
  290.     pushmatrix();
  291.     scale(1.0/(xsize-1),1.0/(ysize-1),1.0);
  292.     for(y=0; y<ysize-1; y++) {
  293.     rectrow(dptr,dptr+xsize,xsize-1,y);
  294.     dptr += xsize;
  295.  
  296.     }
  297.     popmatrix();
  298. }
  299.  
  300. rectrow(y0,y1,n,y)
  301. unsigned long *y0, *y1;
  302. int n, y;
  303. {
  304.     float v0[2];
  305.     int x;
  306.     
  307.     for(x=0; x<n; x++) {
  308.     bgnpolygon();
  309.  
  310.     v0[0] = x;
  311.     v0[1] = y;
  312.     cpack(y0[0]);
  313.     v2f(v0),
  314.  
  315.     v0[0] = x+1;
  316.     v0[1] = y;
  317.     cpack(y0[1]);
  318.     v2f(v0),
  319.  
  320.     v0[0] = x+1;
  321.     v0[1] = y+1;
  322.     cpack(y1[1]);
  323.     v2f(v0),
  324.  
  325.     v0[0] = x;
  326.     v0[1] = y+1;
  327.     cpack(y1[0]);
  328.     v2f(v0),
  329.  
  330.     endpolygon();
  331.     y0++;
  332.     y1++;
  333.     }
  334. }
  335.